


function sendSMS(){
var isValidate = !$('#FD_PHONE').validationEngine('validate');
	//!$('#form1').validationEngine('validateField','#LMS_MOBILE');   -- it is old version 
	if(!isValidate){
		alert("请输入正确的手机号码");
		setTimeout("$('#form1').validationEngine('hide')",2000);
		return false;
	}
	
	$('#resendDiv').show();
	$('#sendDiv').html('发送中');
	$.ajax({
		   url:'../json/prmSmsJson.action', 
		   dataType:'json',
		   cache:false,
		   timeout:10000,
		   async:false,
		   type:'POST',		
		   data:{"mobile":$('#FD_PHONE').val()},
		   success:function(json)
			   {
				  if(json.success==true)
				  {		
				 		$('#sendDiv').html('<br />已向此号码发送免费的验证码短信。' + json.message);
				 		countTime();
				  }
				  else
				  {
					  $('#sendDiv').html("发送短信失败:"+json.message);
					  countTime();
					  /*
					  if(json.message.indexOf("给该手机号发短信的次数达到上限")>-1){
						  var mobile=$('#FD_PHONE').val();				  
						  window.location.href='form3.jsp?rid='+g_rid+'&mobile='+mobile;
					  }
					  */
				  }
				},
			error:function(arg1,arg2)
			   {
					$('#sendDiv').html("<br />发生错误:" + arg1 + " "+arg2);
					countTime();
			   }
		   });

	
	return false;

}
var _token = 0;
var _second = 0;
function countTimeRun(){
	if(_second>=0){
		$('#resendLink').html('(还有'+_second+'秒)重新获取验证码');
		$('#resendLink').css('color','#7E7777');
		$('#resendLink').bind('click',function(){return false;});
		_second--;
	}else{
		clearInterval(_token);
		$('#resendLink').html('重新获取验证码');
		$('#resendLink').css('color','#FF0000');
		$('#resendLink').bind('click',sendSMS);
	}
}

function countTime(){
	_second = 180;
	_token = setInterval(countTimeRun,1000);
}

$(function(){
initCitys();

$.validationEngineLanguage.allRules["chinamobile"] = {			
		"regex": /^(13[0-9]|147|15(0|1|2|3|5|6|7|8|9)|18[0-9])\d{8}$/,
		"alertText": "* 请输入11位手机号"
};

$("#form1").validationEngine({scroll:false}); 
$('#sendLink').click(sendSMS); 
});